#include"Color.hpp"

std::vector<CardsAttributes> InitialCardsColor;
std::vector<CardsAttributes> TargetCardsColor;

// HSL转RGB函数实现
CardsAttributes HSLToRGB(float h, float s, float l) {
    CardsAttributes color;
    
    // 归一化HSL值
    h = fmod(h, 360.0f);  // 色相限制在0-360度
    s = fmax(0.0f, fmin(100.0f, s)) / 100.0f;  // 饱和度0-100转0-1
    l = fmax(0.0f, fmin(100.0f, l)) / 100.0f;  // 亮度0-100转0-1
    
    float c = (1 - fabs(2 * l - 1)) * s;  // 色度
    float x = c * (1 - fabs(fmod(h / 60.0f, 2) - 1));
    float m = l - c / 2;
    
    float r, g, b;
    
    if (h >= 0 && h < 60) {
        r = c; g = x; b = 0;
    } else if (h >= 60 && h < 120) {
        r = x; g = c; b = 0;
    } else if (h >= 120 && h < 180) {
        r = 0; g = c; b = x;
    } else if (h >= 180 && h < 240) {
        r = 0; g = x; b = c;
    } else if (h >= 240 && h < 300) {
        r = x; g = 0; b = c;
    } else {
        r = c; g = 0; b = x;
    }
    
    color.r = static_cast<int>((r + m) * 255);
    color.g = static_cast<int>((g + m) * 255);
    color.b = static_cast<int>((b + m) * 255);
    
    return color;
}

// 生成差异明显的颜色
std::vector<CardsAttributes> GenerateDistinctColors(int count) {
    std::vector<CardsAttributes> colors;
    
    for (int i = 0; i < count; i++) {
        // 在色相环上均匀分布颜色
        float hue = (360.0f * i) / count;
        
        // 固定饱和度和亮度，确保颜色鲜艳且明亮
        CardsAttributes color = HSLToRGB(hue, 70.0f, 50.0f);
        
        colors.push_back(color);
    }
    
    return colors;
}